/**
 * This class is a container for all things related to a transaction on a pump or the register.
 *
 * @author Steve, Jesus
 */
package uicgas.globaldata;

import java.io.Serializable;

public class Transaction extends MessagePayload implements Serializable
{
	private static final long serialVersionUID = 1098160447548167031L;

	private double ammountPumpedDollars;
	private double ammountPumpedGallons;
	private CreditCard validCreditCard;
	private int pumpID = -1;
	private int destinationID = -1;

	/**
	 * A generic constructor for a transaction
	 * @author Steve, Jesus
	 */
	public Transaction()
	{
		ammountPumpedDollars = 0.00;
		ammountPumpedGallons = 0.00;
		validCreditCard = new CreditCard();
	}

	/**
	 * A generic constructor for a transaction
	 * @author Steve, Jesus
	 * @param dollars - The dollar amount pumped by a motorist during a transaction
	 * @param gallons - The Number of gallons pumped by a motorist during a transaction 
	 * @param card - The Credit card used for the transaction
	 */
	public Transaction(double dollars, double gallons, CreditCard card)
	{
		ammountPumpedDollars = dollars;
		ammountPumpedGallons = gallons;
		validCreditCard = card;
	}

	/**
	 * A generic constructor for a transaction
	 * @author Steve, Jesus
	 * @param dollars - The dollar amount pumped by a motorist during a transaction
	 * @param gallons - The Number of gallons pumped by a motorist during a transaction 
	 * @param card - The Credit card used for the transaction
	 * @param pumpID - the ID of the pump used in the transaction
	 */
	public Transaction(double dollars, double gallons, CreditCard card,
			int pumpID)
	{
		ammountPumpedDollars = dollars;
		ammountPumpedGallons = gallons;
		validCreditCard = card;
		this.pumpID = pumpID;
	}

	public Transaction(double dollars, double gallons, CreditCard card,
			int pumpID, int registerID)
	{
		ammountPumpedDollars = dollars;
		ammountPumpedGallons = gallons;
		validCreditCard = card;
		this.pumpID = pumpID;
		this.destinationID = registerID;
	}

	/**
	 * Sets the amount in dollars pumped during a transaction.
	 * @author HONG
	 * @param dollars - The dollar amount pumped by a motorist during a transaction
	 */
	public void setDollars(double dollars)
	{
		ammountPumpedDollars = dollars;
	}

	/**
	 * sets the amount in gallons pumped during a transaction.
	 * @author HONG
	 * @param gallons - The Number of gallons pumped by a motorist during a transaction 
	 */
	public void setGallons(double gallons)
	{
		ammountPumpedGallons = gallons;
	}

	/**
	 * method for getting the amount pumped during a transaction.
	 * @return Returns a double int of the Dollar amount pumped during a transaction.
	 */
	public double getFinalDollars()
	{
		return ammountPumpedDollars;
	}

	/**
	 * get the Name on the Credit Card
	 * @return String
	 */
	public String getCreditCardName()
	{
		return validCreditCard.getFullName();
	}

	/**
	 * get the last four digits of the credit card used in the transaction.
	 * @return String
	 */
	public String getLast4DigitsToString()
	{
		return validCreditCard.last4CC();
	}

	/**
	 * calculate a receipt string.
	 * @return String
	 */
	public String toPrint()
	{
		String result = "";

		result += "UIC GAS\n";
		result += "\nGallons: " + ammountPumpedGallons;
		result += "\nDollars: " + ammountPumpedDollars;
		if (validCreditCard != null)
		{
			result += "\nCard Holder: " + validCreditCard.getFullName();
			result += "\nCard No.: " + validCreditCard.last4CC();
		}

		return result;
	}

	/**
	 * Get the ID of the pump used during the transaction.
	 * @return int
	 */
	public int getPumpID()
	{
		return pumpID;
	}

	/**
	 * Provides the id of the intended recipient 
	 * of the transaction information for storage in the transaction.
	 * @param destinationID - The ID of the recipient
	 */
	public void setDestinationID(int destinationID)
	{
		this.destinationID = destinationID;
	}

	/**
	 * gets the ID of the recipient
	 * @return int
	 */
	public int getDestinationID()
	{
		return destinationID;
	}

	public CreditCard getCreditCardInfo()
	{
		return validCreditCard;
	}
}
